const { default: api } = require("../../../../common/api");
const { default: constant } = require("../../../../common/constant");
const { gioPhoneRecallLog } = require("../../../../common/gioHandler");

// pages/im/com/auth-card-item/auth-card-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    userID: String,
    item: Object,
  },

  /**
   * 组件的初始数据
   */
  data: {
    cooperationId:'', //房源id
    toUserId:'',//对方的用户id
    isVmShow:false,//控制打电话弹窗的显示
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handlePhone() {
      const { userID, item } = this.data;
      const isMe = userID === item.from;
      const callType = isMe ? constant.house_visiter : constant.house_owner; 
      gioPhoneRecallLog(callType)

      if (isMe) {
        wx.showToast({ icon: 'none', title: '不能自己打给自己哦，试试点击上方打给TA！', })

      } else {
        const { payload } = this.data.item
        this.setData({
          isVmShow:true,
          toUserId:payload.agentId,
          cooperationId:payload.cooperationId
        })
      }
    },
    handleVmVisible(e) {
      this.setData({
        isVmShow: e.detail.visible
      });
    },

    handleView() {
      wx.previewImage({
        urls: this.data.item.payload.files,
      });
    }
  }
})
